/*
 * @Author: zhangfeng
 * @Date: 2023-12-25 16:35:37
 * @LastEditTime: 2023-12-28 15:51:24
 * @LastEditors: zhangfeng
 * @Description:
 * @FilePath: \nodeapi\src\server\role-user.server.js
 * © 2023 张峰，All rights reserved.
 */
const RoleUser = require("../model/role-user.model");

class RoleUserServer {
  // 写入数据
  async createServer(roleUserArray) {
    const result = await RoleUser.bulkCreate(roleUserArray);
    return result.dataValues;
  }

  // userId 查找roleId
  async getRolesByUserId(userId) {
    const result = await RoleUser.findAll({
      attributes: ["roleId"],
      where: {
        userId,
      },
    });
    return result.map((item) => item.roleId);
  }
  // userId修改角色roleId
  async updateRolesByUserId(userId, roleId) {
    const result = await RoleUser.update(
      { roleId },
      {
        where: {
          userId,
        },
      }
    );
    return result;
  }
}

module.exports = new RoleUserServer();
